<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./site/public/music/playlist.php, $Author:  $ */

// Get the DB connection
$oDb = &Database::get();

// Get the request class
$oReq = &App::getRequest();

// Make sure we have an ID
if ( $iId = $oReq->get('id') )
{
	// Lets make this page an XML
	header("content-type:text/xml;charset=utf-8");

	// Lets get the mode of the page
	$sType = $oReq->get('mode');

	echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
	echo "	<title>". App::getSetting('site_name') ."</title>\n";
	echo "	<info>". App::getParam('url') ."</info>\n";
	echo "	<trackList>\n";

	if ( $sType == 'playlist' )
	{
		$aRows = $oDb->getRows("SELECT s.song_id, s.song_title, s.album_id, u.musician_name FROM
		". App::getT('music_song') ." AS s,
		". App::getT('music_musician') ." AS u ".
		" WHERE s.album_id = '". $iId ."' AND s.song_is_approved = '1' AND s.musician_id = u.musician_id ");

		foreach($aRows as $aRow)
		{
			echo "		<track>\n";
			echo "			<title>". $aRow['song_title'] ."</title>\n";
			echo "			<creator>". $aRow['musician_name'] ."</creator>\n";
			echo "			<location>". $aRow['song_id'] .".mp3</location>\n";
			echo "			<info>". App::makeUrl('public.music.song',array('id' => $aRow['song_id'])) ."</info>\n";
			echo "			<image>". App::getParam('music.album.pic.url') ."". $aRow['album_id'] .".jpg</image>\n";
			echo "		</track>\n";
		}
	}
	elseif ( $sType == 'user_playlist' )
	{
		$aRows = $oDb->getRows("SELECT s.song_id, s.song_title, s.album_id, u.musician_name FROM
		". App::getT('music_song') ." AS s,
		". App::getT('music_musician') ." AS u ".
		" WHERE s.user_id = '". $iId ."' AND s.song_is_approved = '1' AND s.musician_id = u.musician_id");

		foreach($aRows as $aRow)
		{
			echo "		<track>\n";
			echo "			<title>". $aRow['song_title'] ."</title>\n";
			echo "			<creator>". $aRow['musician_name'] ."</creator>\n";
			echo "			<location>". $aRow['song_id'] .".mp3</location>\n";
			echo "			<info>". App::makeUrl('public.music.song',array('id' => $aRow['song_id'])) ."</info>\n";
			echo "			<image>". App::getParam('music.album.pic.url') ."". $aRow['album_id'] .".jpg</image>\n";
			echo "		</track>\n";
		}
	}
	elseif ( $sType == 'admin_view' )
	{
		$aRow = $oDb->getRow("SELECT s.song_id, s.song_title, s.album_id, u.musician_name FROM
		". App::getT('music_song') ." AS s,
		". App::getT('music_musician') ." AS u ".
		" WHERE s.song_id = '". $iId ."' AND s.musician_id = u.musician_id ");

		echo "		<track>\n";
		echo "			<title>". $aRow['song_title'] ."</title>\n";
		echo "			<creator>". $aRow['musician_name'] ."</creator>\n";
		echo "			<location>". $aRow['song_id'] .".mp3</location>\n";
		echo "			<info>". App::makeUrl('public.music.song',array('id' => $aRow['song_id'])) ."</info>\n";
		echo "			<image>". App::getParam('music.album.pic.url') ."". $aRow['album_id'] .".jpg</image>\n";
		echo "		</track>\n";
	}
	else
	{
		$aRow = $oDb->getRow("
			SELECT s.song_id, s.song_title, s.album_id, u.musician_name FROM
			". App::getT('music_song') ." AS s
				JOIN ". App::getT('music_musician') ." AS u
			WHERE s.song_id = '". $iId ."' AND s.song_is_approved = '1' AND s.musician_id = u.musician_id 
		");

		echo "		<track>\n";
		echo "			<title>". $aRow['song_title'] ."</title>\n";
		echo "			<creator>". $aRow['musician_name'] ."</creator>\n";
		echo "			<location>". $aRow['song_id'] .".mp3</location>\n";
		echo "			<info>". App::makeUrl('public.music.song',array('id' => $aRow['song_id'])) ."</info>\n";
		echo "			<image>". App::getParam('music.album.pic.url') ."". $aRow['album_id'] .".jpg</image>\n";
		echo "		</track>\n";
	}

	echo "	</trackList>\n";
	echo "</playlist>\n";
	exit;
}
?>